<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:p="http://primefaces.prime.com.tr/ui"
      xmlns:c="http://java.sun.com/jsp/jstl/core">

    <ui:composition template="/template/DefaultTemplate.xhtml">

        <ui:define name="content">
            <h:form prependId="false">
                <p:panel toggleable="true" id="inventoryView" header="Inventory Overview">
                    <h:panelGrid columns="3">
                        <h:outputLabel value="Total Usage= #{completedGoodsEntityController.totalCGUsage}"/>
                        <p:spacer width="60" height="10"/>
                        <h:outputLabel value="Total Capacity= #{completedGoodsEntityController.totalCGCapacity}"/>
                    </h:panelGrid>

                    <h:panelGrid cellpadding="5" width="400" border="3" columns="4">
                        <h:outputText value=""/>
                        <h:outputText value="Unreserved"/>
                        <h:outputText value="Reserved"/>
                        <h:outputText value="Total"/>

                        <h:outputText value="Classic Nutri Bar (Nuts)"/>
                        <h:outputLabel style="table-layout: center" value="#{completedGoodsEntityController.totalClassicNutriBarNuts}"/>
                        <h:outputLabel style="table-layout: center" value="#{completedGoodsEntityController.totalReservedClassicNutriBarNuts}"/>
                        <h:outputLabel style="table-layout: center" value="#{completedGoodsEntityController.totalClassicNutriBarNuts + completedGoodsEntityController.totalReservedClassicNutriBarNuts}"/>

                        <h:outputText value="Classic Nutri Bar (Fruits)"/>
                        <h:outputLabel style="text-align: center" value="#{completedGoodsEntityController.totalClassicNutriBarFruits}"/>
                        <h:outputLabel style="table-layout: center" value="#{completedGoodsEntityController.totalReservedClassicNutriBarFruits}"/>
                        <h:outputLabel style="table-layout: center" value="#{completedGoodsEntityController.totalClassicNutriBarFruits + completedGoodsEntityController.totalReservedClassicNutriBarFruits}"/>

                        <h:outputText value="Premium Power Bar (Chocolate Nuts)"/>
                        <h:outputLabel style="text-align: center" value="#{completedGoodsEntityController.totalPremiumPowerBarNuts}"/>
                        <h:outputLabel style="text-align: center" value="#{completedGoodsEntityController.totalReservedPremiumPowerBarNuts}"/>
                        <h:outputLabel style="table-layout: center" value="#{completedGoodsEntityController.totalPremiumPowerBarNuts + completedGoodsEntityController.totalReservedPremiumPowerBarNuts}"/>

                        <h:outputText value="Premium Power Bar (Redcurrant Fruits)"/>
                        <h:outputLabel style="text-align: center" value="#{completedGoodsEntityController.totalPremiumPowerBarFruits}"/>
                        <h:outputLabel style="text-align: center" value="#{completedGoodsEntityController.totalReservedPremiumPowerBarFruits}"/>
                        <h:outputLabel style="table-layout: center" value="#{completedGoodsEntityController.totalPremiumPowerBarFruits + completedGoodsEntityController.totalReservedPremiumPowerBarFruits}"/>
                    </h:panelGrid>

                </p:panel>
                <br/>
                <p:panel id="dataGridPanelId">
                <p:dataGrid widgetVar="dataGrid" id="dataGrid" var="item" value="#{completedGoodsLocationEntityController.items}" columns="5">  

                    <p:column >  
                        <p:panel header="#{item.areaCode}" style="text-align:center">  

                            <h:outputLabel id="usageLabel" value="Usage: #{item.usageCase}/#{item.capacityCase}"/>
                            <p:poll interval="20" update="pbAjax" widgetVar="poll" />  

                            <p:progressBar id="pbAjax" widgetVar="pbAjax" ajax="true" value="#{item.usageCase/10}"/>

                            <br />
                            <p:commandButton image="ui-icon ui-icon-search" update="cgLocationDetail" oncomplete="cgLocationDialog.show()" title="View Detail">  

                                <f:setPropertyActionListener value="#{item}"   
                                                             target="#{completedGoodsEntityController.viewLocation}" />  
                            </p:commandButton> 

                            <p:commandButton id="expiringButton" rendered="#{item.anyExpiring==true}" image="ui-icon ui-icon-alert" update="expiringBatchTable" oncomplete="cgExpirationDialog.show()" title="View Expiring Batches">  

                                <f:setPropertyActionListener value="#{item}"   
                                                             target="#{completedGoodsEntityController.expiringCGInLocation}" /> 

                            </p:commandButton>  

                        </p:panel>  
                    </p:column>  

                </p:dataGrid>  
                </p:panel>
            </h:form>


            <p:dialog header="Location Detail" widgetVar="cgLocationDialog" width="400" height="210" modal="true">  
                <p:outputPanel id="cgLocationDetail" style="text-align:center;" layout="block">  

                    <h:panelGrid width="373" border="3" columns="2" cellpadding="5">  
                        <h:outputLabel for="ClassicNutriBarNuts" value="Classic Nutri Bar (Nuts): " />  
                        <h:outputText id="ClassicNutriBarNuts" value="#{completedGoodsEntityController.classicNutriBarNuts}" />  

                        <h:outputLabel for="ClassicNutriBarFruits" value="Classic Nutri Bar (Fruits): " />  
                        <h:outputText id="ClassicNutriBarFruits" value="#{completedGoodsEntityController.classicNutriBarFruits}" />  

                        <h:outputLabel for="PremiumPowerBarNuts" value="Premium Power Bar (Chocolate Nuts): " />  
                        <h:outputText id="PremiumPowerBarNuts" value="#{completedGoodsEntityController.premiumPowerBarNuts}" />  

                        <h:outputLabel for="PremiumPowerBarFruits" value="Premium Power Bar (Redcurrant Fruits): " />  
                        <h:outputText id="PremiumPowerBarFruits" value="#{completedGoodsEntityController.premiumPowerBarFruits}" />  

                    </h:panelGrid>  
                </p:outputPanel>  
            </p:dialog> 

            <p:dialog id="expirationDialog" header="Completed Goods Expiring Within 30 days" widgetVar="cgExpirationDialog" width="600" height="250" modal="true">  
                <h:form prependId="false">
                    <p:panel id="expirationDialogPanel">
                    <p:dataTable id="expiringBatchTable" var="expiringBatch" value="#{completedGoodsEntityController.expiringLocationToQuantities}" >
                        <p:column headerText="Batch ID">
                            <h:outputLabel for="batchId" value="#{expiringBatch.inventory.batch.id}" />
                        </p:column>
                        <p:column headerText="Expiry Date">
                            <h:outputLabel for="batchExpiryDate" value="#{expiringBatch.inventory.batch.expiryDate}" />
                        </p:column>
                        <p:column headerText="Product">
                            <h:outputLabel for="batchProductName" value="#{expiringBatch.inventory.batch.product.productName}" />

                        </p:column>
                        <p:column headerText="Quantity">
                            <h:outputLabel for="batchQuantity" value="#{expiringBatch.quantity}" />
                        </p:column>
                        <p:column>
                            <p:commandButton ajax="false" value="Remove">
                                <f:setPropertyActionListener target="#{completedGoodsEntityController.locationToRemove}"
                                                             value="#{expiringBatch}"/>                                                         
                            </p:commandButton>
                        </p:column>

                    </p:dataTable>
                    </p:panel>
                </h:form>
            </p:dialog> 


        </ui:define>
    </ui:composition>

</html>
